﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _8.ReplaceWholeWord
{
    class ReplaceWholeWord
    {
        static void Main(string[] args)
        {
            StreamReader reader = new StreamReader(@"..\..\ReplaceWholeWord.cs");
            StreamWriter writer = new StreamWriter(@"..\..\Replaced.txt");
            StringBuilder word = new StringBuilder();
            StringBuilder line = new StringBuilder();
            using (writer)
            {
                using (reader)
                {
                    while (reader.EndOfStream != true)
                    {
                        string oneLine = reader.ReadLine();
                        foreach (char symbol in oneLine)
                        {
                            if ((symbol >= '0' && symbol <= '9') || (symbol >= 'A' && symbol <= 'Z') || (symbol >= 'a' && symbol <= 'z'))
                            {
                                word.Append(symbol);
                            }
                            else
                            {
                                string tempWord = word.ToString();
                                if ("start".ToUpper() == word.ToString().ToUpper())
                                {
                                    tempWord = "finish";
                                }
                                //finish finish finish finish finish finish finish finish finish finish finish finish 
                                //start start start start start start start start start start start start start start 
                                line.Append(tempWord);
                                line.Append(symbol);
                                word.Clear();
                            }
                        }
                        writer.WriteLine(line.ToString());
                        line.Clear();
                        writer.Flush();
                    }
                }
            }
        }
    }
}